<?php
/**
 *
 * @author Tongle Xu <xutongle@gmail.com> 2013-11-18
 * @copyright Copyright (c) 2003-2103 tintsoft.com
 * @license http://www.tintsoft.com
 * @version $Id$
 */
namespace Leaps\Cache\Adapter;
use Leaps\Cache\AdapterInterface;
use Leaps\Cache\Section;

class Arrays implements AdapterInterface {

    /**
     * 数组的存储值。
     *
     * @var array
     */
    protected $storage = array();

    /**
     * (non-PHPdoc)
     * @see \Leaps\Cache\StoreInterface::get()
    */
    public function get($key)
    {
        if (array_key_exists($key, $this->storage))
        {
            return $this->storage[$key];
        }
    }

    /**
     * (non-PHPdoc)
     * @see \Leaps\Cache\StoreInterface::set()
     */
    public function set($key, $value, $minutes)
    {
        $this->storage[$key] = $value;
    }

    /**
     * (non-PHPdoc)
     * @see \Leaps\Cache\StoreInterface::forever()
     */
    public function forever($key, $value)
    {
        return $this->put($key, $value, 0);
    }

    /**
     * (non-PHPdoc)
     * @see \Leaps\Cache\StoreInterface::delete()
     */
    public function delete($key)
    {
        unset($this->storage[$key]);
    }

    /**
     * (non-PHPdoc)
     * @see \Leaps\Cache\StoreInterface::flush()
     */
    public function flush()
    {
        $this->storage = array();
    }

    /**
     * Begin executing a new section operation.
     *
     * @param  string  $name
     * @return \Leaps\Cache\Section
     */
    public function section($name)
    {
        return new Section($this, $name);
    }
}